import request from "@/utils/request";

export function getMenusTree(pid) {
  return request({
    url: "rest/api/menu/lazy?pid=" + pid,
    method: "get"
  });
}

export function getMenus(params) {
  return request({
    url: "rest/api/menu/all",
    method: "get",
    params
  });
}

export function getMenuSuperior(ids) {
  const data = ids.length || ids.length === 0 ? ids : Array.of(ids);
  return request({
    url: "rest/api/menu/superior",
    method: "post",
    data
  });
}

export function buildMenus() {
  return request({
    url: "rest/api/menu/build",
    method: "get"
  });
}

export function add(data) {
  return request({
    url: "rest/api/menu/menus",
    method: "post",
    data
  });
}

export function del(ids) {
  return request({
    url: "rest/api/menu/menus/del",
    method: "post",
    data: ids
  });
}

export function edit(data) {
  return request({
    url: "rest/api/menu/menus/update",
    method: "post",
    data
  });
}

export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus };
